
Page({
    data: {
      pageType: '',
      contactList: [], // 客服列表
      project: {}, // 项目参数
      basicInformation: [], // 基本参数
      salesInformation: [], // 销售信息
      overview: [], // 楼盘概况
      layoutList: [], // 楼盘户型列表信息
      html: "<div></div>"
    },
    onLoad(t) {
      this.setData({
        pageType: t.pageType
      })
      this.getHtml();
    },
    onReady() {
      // this.videoContext = wx.createVideoContext('property__video')
    },
    onShow() {},
    onHide() {},
    onUnload() {},
    onPullDownRefresh() {},
    onReachBottom() {},
    phoneCall(e) {
      let target = e.currentTarget.dataset;
      wx.makePhoneCall({
        phoneNumber: target.phone
      })
    },
    toPage(e) { // 页面跳转
      let target = e.currentTarget.dataset;
      if (target.url) {
        wx.navigateTo({ url: target.url });
      } else {
        console.warn('Not Page Url')
      }
    },
    toWebview(e) {
      let target = e.currentTarget.dataset;
      let URI = encodeURIComponent(target.url);
      wx.navigateTo({ url: `/page/webview/webview?to=${URI}` });
    },
    previewImage(e) {
      let target = e.currentTarget.dataset;
      wx.previewImage({
        current: target.img, // 当前显示图片的http链接
        urls: [target.img] // 需要预览的图片http链接列表
      })
    },
    
    getLayout() {
      let local = wx.getStorageSync('_propertyDetail')
      let listTemp = local ? (local.houseLayoutList && local.houseLayoutList.length > 0) ? local.houseLayoutList : local.prototypeRoomList || [] : []
      listTemp.map(item => {
        item.name = local.name || ''
      })
      this.setData({
        layoutList: listTemp
      })
    },
    // ------------------------------------
    getHtml() {
      let local = wx.getStorageSync('_propertyDetail'), html = '<div></div>', that = this;
      switch (this.data.pageType) {
        case 'value': // 项目价值
          html = local ? local.projectValueText : '<div></div>'
          wx.setNavigationBarTitle({ title: "项目价值" })
          break;
        case 'appreciation': // 项目鉴赏
          html = local ? local.projectAppreciateText : '<div></div>'
          wx.setNavigationBarTitle({ title: "项目鉴赏" })
          break;
        case 'video': // 精彩视角
          html = local ? local.wonderfulViewText : '<div></div>'
          wx.setNavigationBarTitle({ title: "精彩视角" })
          break;
        case 'layout': // 样板间
          // html = local ? local.houseLayoutText : '<div></div>'
          html = local ? local.prototypeRoomText : '<div></div>'
          wx.setNavigationBarTitle({ title: "样板间" })
          this.getLayout();
          break;
        case 'room': // 楼盘户型
          // html = local ? local.prototypeRoomText : '<div></div>'
          html = local ? local.houseLayoutText : '<div></div>'

          wx.setNavigationBarTitle({ title: "楼盘户型" })
          break;
        case 'parameter':  // 项目参数
          wx.setNavigationBarTitle({ title: "项目参数" });
          let basicInformation = [{
            key: '楼盘特色',
            value: local.houseFeature
          }, {
            key: '参考单价',
            value: local.unitPrice
          }, {
            key: '参考总价',
            value: local.totalPrice
          }, {
            key: '建筑面积',
            value: local.totalFloorArea
          }, {
            key: '物业类型',
            value: local.propertyType
          }, {
            key: '产品类型',
            value: local.productType
          }, {
            key: '装修标准',
            value: local.decorationStandard
          }, {
            key: '产权年限',
            value: local.propertyRight
          }, {
            key: '开 发 商',
            value: local.developers
          }, {
            key: '楼盘地址',
            value: local.houseAddress
          }], salesInformation = [{
            key: '售卖状态',
            value: local.houseStatus
          }, {
            key: '售 楼 处',
            value: local.salesOffice
          }, {
            key: '最新开盘',
            value: local.openTime?local.openTime.slice(0, 19):'---'
          }, {
            key: '最近交房',
            value: local.closeTime?local.closeTime.slice(0, 19):'---'
          }], overview = [{
            key: '占地面积',
            value: local.occupiedArea
          }, {
            key: '总建筑面积',
            value: local.totalFloorArea
          }, {
            key: '容 积 率',
            value: local.plotRatio
          }, {
            key: '绿 化 率',
            value: local.greenRate
          }, {
            key: '车位配比',
            value: local.stallMatch
          }, {
            key: '物业费用',
            value: local.propertyCost
          }]
    
          that.setData({
            project: local,
            basicInformation: basicInformation,
            salesInformation: salesInformation,
            overview: overview
          })
          break;
        case 'contact':  // 联系售楼
          this.getContactList();
          wx.setNavigationBarTitle({ title: "联系售楼" });
          break;
        default:
          break;
      }
      if (html) {
        html = html.replace(/\<img/gi, '<img style="max-width:100%;width:100%;height:auto"')
      }
      setTimeout(() => {
        // WxParse.wxParse('article', 'html', html, that, 5);
          this.setData({
            html: html || "<div></div>"
          })
      }, 500);
    },
    getContactList() { // 获取客服列表
      getApp().api.getServiceList().then(res => {
        this.setData({
          contactList: res.data || []
        })
      })
    }
  })
